ARG JAVACOMPILEIMAGE
ARG TARGETPLATFORM
ARG OS_ARCH

# 指定基础镜像，这是分阶段构建的前期阶段
FROM $JAVACOMPILEIMAGE as builder
# 执行工作目录
WORKDIR target
# 配置参数
ARG JAR_FILE=target/*.jar
# 将编译构建得到的jar文件复制到镜像空间中
COPY ${JAR_FILE} application.jar
#RUN unzip application.jar && mkdir -p BOOT-INF/lib2 && mv BOOT-INF/lib/lhm-*.jar BOOT-INF/lib2
RUN unzip application.jar

FROM --platform=$OS_ARCH $TARGETPLATFORM

ARG EXPOSE_PORT
ARG JAR_FILE
ARG MAINCLASS

ARG DEPENDENCY=target
COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib
#COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib2 /app/lib2
COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app

EXPOSE ${EXPOSE_PORT}

ARG CACHEFROM
LABEL description=" cache from ${CACHEFROM}"

ENV JAVA_OPTS ""
ENV AGENT_AFTER_JAR ""
ENV MAINCLASS ${MAINCLASS}

CMD java ${JAVA_OPTS} -Dspring.profiles.active=docker -Dservice_name=${MAINCLASS} -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/opt/logs/jvm/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/logs/jvm/dump.hprof -Djava.security.egd=file:/dev/./urandom -Denv=dev -Duser.timezone=GMT+08 ${AGENT_AFTER_JAR}  -cp app:app/lib2/*:app/lib/*  ${MAINCLASS}
